//
//  FileWindow.h
//  Editor
//
//  Created by Jeppe Nielsen on 10/19/14.
//  Copyright (c) 2014 Jeppe Nielsen. All rights reserved.
//

#pragma once
#include "ToolWindow.hpp"
#include <QtWidgets/QtWidgets>
#include "AngelScriptSyntaxHighlighter.hpp"
#include "TextFile.hpp"
#include <map>

class FileWindow : public ToolWindow {
    Q_OBJECT
protected:
    std::string GetName();
    void OnCreate();
    void OnSave();
    void ProjectChanged(Nano::Property<Context*, Project*>::EventData e);

private:
    QTreeView* treeView;
    QFileSystemModel* fileSystemModel;
    QTabWidget* tabWidget;
    AngelScriptSyntaxHighlighter syntaxHighlighter;
    
    typedef std::map<QString, TextFile*> TextFiles;
    TextFiles textFiles;
    
    void OpenTextFile(QString filename);
    
    TextFiles::iterator GetTextFileFromTabIndex(int index);
    
    bool selectionFromTreeView;
    
    QMenu* contextMenu;
    QAction* menuRename;
    
    void CreateContextMenu();
    
private slots:
    void SelectionChanged(const QModelIndex &current, const QModelIndex &previous);
    void TabClosedClicked(int index);
    void FileRenamed(const QString &path, const QString &oldName, const QString &newName);
    void CurrentTabChanged(int index);
    void SelectionDoubleClicked(const QModelIndex& current);
    
    void onCustomContextMenu(const QPoint& point);
    
};